package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.po.AdminConfigExpressPO;
import com.cskaoyan.bean.po.AdminConfigMallPO;
import com.cskaoyan.bean.po.AdminConfigOrderPO;
import com.cskaoyan.bean.po.AdminConfigWxPO;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.admin.AdminConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 配置管理 --> 商场配置 --> mall express
 *
 * @author : Caspar
 * @since : 2022.06.26 18:37
 */
@RestController
@RequestMapping("admin/config")
public class AdminConfigController {


    @Autowired
    AdminConfigService adminConfigService;

    /**
     * 从market_system表中查询商场配置并回显
     *
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 18:42
     */
    @GetMapping("mall")
    public BaseRespVo mallResponse() {

        AdminConfigMallPO adminConfigMallPO = adminConfigService.queryMallConfig();
        return BaseRespVo.ok(adminConfigMallPO);
    }

    /**
     * 修改商场的配置信息
     *
     * @param adminConfigMallPO
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 19:27
     */
    @PostMapping("mall")
    public BaseRespVo mallUpdate(@RequestBody AdminConfigMallPO adminConfigMallPO) {
        adminConfigService.updateMarketMallConfig(adminConfigMallPO);
        return BaseRespVo.ok();
    }

    /**
     * 从market_system表中查询运费配置并回显
     *
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 20:19
     */
    @GetMapping("express")
    public BaseRespVo expressResponse() {

        AdminConfigExpressPO adminConfigExpressPO = adminConfigService.queryExpressConfig();
        return BaseRespVo.ok(adminConfigExpressPO);
    }

    /**
     * 从market_system表中修改运费配置并回显
     *
     * @param adminConfigExpressPO
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 20:31
     */
    @PostMapping("express")
    public BaseRespVo expressUpdate(@RequestBody AdminConfigExpressPO adminConfigExpressPO) {

        adminConfigService.updateMarketExpressConfig(adminConfigExpressPO);
        return BaseRespVo.ok();
    }

    /**
     * 从market_system表中查询订单管理的配置并回显
     *
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 20:38
     */
    @GetMapping("order")
    public BaseRespVo orderResponse() {
        AdminConfigOrderPO adminConfigOrderPO = adminConfigService.queryOrderConfig();
        return BaseRespVo.ok(adminConfigOrderPO);
    }

    /**
     * 修改订单管理的配置
     *
     * @param adminConfigOrderPO
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 21:15
     */
    @PostMapping("order")
    public BaseRespVo orderUpdate(@RequestBody AdminConfigOrderPO adminConfigOrderPO) {
        adminConfigService.updateMarketOrderConfig(adminConfigOrderPO);
        return BaseRespVo.ok();
    }

    /**
     * 从market_system表中查询小程序的配置并回显
     *
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 20:38
     */
    @GetMapping("wx")
    public BaseRespVo wxResponse() {
        AdminConfigWxPO adminConfigWxPO = adminConfigService.queryWxConfig();
        return BaseRespVo.ok(adminConfigWxPO);
    }

    /**
     * 从market_system表中修改小程序的配置
     *
     * @param adminConfigWxPO
     * @return com.cskaoyan.bean.vo.BaseRespVo
     * @author: Caspar CXC
     * @since 2022/06/26 22:05
     */
    @PostMapping("wx")
    public BaseRespVo wxUpdate(@RequestBody AdminConfigWxPO adminConfigWxPO) {
        adminConfigService.updateMarketWxConfig(adminConfigWxPO);
        return BaseRespVo.ok();
    }

}
